<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_goodsoption extends Controller_Abstract {
	
	/**
	 * 商品规格
	 */
	function actionList()
	{
		$this->union_table = goodsoption::meta();
		$append_data=array("acct_id"=>$_SESSION['acct']['id'],"goodsid"=>$this->_context->goodsid);
		$this->lists($append_data);
		$this->_view['goodsid'] = $this->_context->goodsid;
	}
	 
	/**
	 * 商品规格
	 */
	 
	function actionAdd() {
		 //设置要操作的表单，并设置自动插入方式
	    if($this->_context->isGET()){
	    	if(!empty($this->_context->id)){
	    		$goodsoption = goodsoption::find('id=?',$this->_context->id)->getOne();
	    		$this->_view['goodsoption'] = $goodsoption;
	    		$this->_view['goodsid'] = $goodsoption->goodsid;
	    	}else{
	    		$goods_id = $this->_context->goodsid;
	    		$this->_view['goodsid'] = $goods_id;
	    	}
	    }
		if($this->_context->isPOST())
		{
			if(!empty($this->_context->id)){
				$goods = goodsoption::find('id=?',$this->_context->id)->getOne();
				$goods->title=trim($this->_context->title);
				$goods->thumb=trim($this->_context->thumb);
				$goods->marketprice=floatval($this->_context->marketprice);
				$goods->productprice = floatval($this->_context->productprice);
				$goods->stock = intval($this->_context->stock);
				$goods->displayorder = intval($this->_context->displayorder);
				$goods->goodsid=intval($this->_context->goodsid);
		        $goods->save(0,'update');
			}else{
				$goods = new goodsoption;
				$goods->acct_id=$_SESSION['acct']['id'];
				$goods->title=trim($this->_context->title);
				$goods->thumb=trim($this->_context->thumb);
				$goods->marketprice=floatval($this->_context->marketprice);
				$goods->productprice = floatval($this->_context->productprice);
				$goods->stock = intval($this->_context->stock);
				$goods->displayorder = intval($this->_context->displayorder);
				$goods->goodsid=intval($this->_context->goodsid);
				$goods->save(0,'create');
			}
			if(!$_POST['id'])	{
	            Syslog::logs ( '添加商品规格,id :' . $goods->id );
	        }else{
	            Syslog::logs ( '编辑商品规格,id :' . $goods->id );
	        }
	        $this->_context->forwardUrl = url("goodsoption/list")."/goodsid/".$goods->goodsid;
			$this->success('编辑成功');
	     }
	     
	}
	 
	/**
	 * 删除商品规格
	 */
	function actionDel() {
	     Syslog::logs("删除商品规格，ID：".print_r($this->_context->ids,true));
	     $this->union_table = goodsoption::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}


}


